import { _decorator, Component, isCCObject, ResolutionPolicy, screen, Size, view,Node, Prefab, instantiate, UITransform, resources, assetManager, AudioSource, js, Canvas, AssetManager } from 'cc';
import { ResManager } from '../GScript/core/modules/res/ResManager';
import { UIManager } from '../GScript/core/modules/ui/UIManager';
const { ccclass, property } = _decorator;



@ccclass('Boost')
export class Boost extends Component {

    @property(Canvas) 
    private canvas2d: Canvas = null;
    @property(Node) 
    private toReleaseNode: Node = null;

    
    private loadBundle(bundleName:string):Promise<AssetManager.Bundle>{
        return new Promise<AssetManager.Bundle>(rs => {
            assetManager.loadBundle(bundleName,(e,asset) => {
                if(e){
                    console.error(e);
                    rs(null);
                    return;
                }
                rs(asset);
            })
        })
    }

    async start(){
        await this.loadBundle("GScriptBN");
        const gCtr:any = this.node.addComponent("GCtr");
        await gCtr.init({
            canvas2d:this.canvas2d,
            releaseBoostFun:()=>{
                if(this.toReleaseNode === null){
                    return
                }

                this.toReleaseNode.destroy();
                this.toReleaseNode = null;
            }
        })
    }
}